<?php

require_once 'control/common/calendar/form.php';
require_once 'view/adm/calendar/event.edit.php';
require_once 'view/pub/calendar/event.thanks.php';
require_once APP_ROOT . 'model/common/session.php';
require_once APP_ROOT . 'model/common/user.php';
require_once APP_ROOT . "model/common/site.php";

require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';

class EventEditPage extends PageController {

	var $form;
	var $view;

    function EventEditPage() {
        parent::PageController();
        $this->form =& new EventFormController();

        $logged_in = Session::isLogin();
        if ($logged_in) {
        	//$user_data =& Session::getUserArray();
        	$user_id = Session::getUserId();
            //$is_admin = User::isExistingUserAdmin($user_data);
            //$is_staff = User::isExistingUserStaffAuthor($user_data);
            $is_admin = User::isUserAdmin($user_id);
            $is_staff = User::isUserStaffArticleWriter($user_id);
            if ( $is_admin &&  !$is_staff) $is_staff = true;

        }

        //if ( $is_admin ) print 'Admin user!';
        //if ( $is_staff ) print 'Staff user!';

        $this->form->setUserType($is_admin,$is_staff);
        $this->addChild('EventForm', $this->form);
        $this->setDefaultChild('EventForm');


        $mytemplate = 'pub/calendar/event.edit.html';
        $mytemplate2 = 'pub/calendar/thanks.html';

        // pass form controller as a parameter
        // /pub/calendar/event.edit.html
        // /common/events/event.edit.html
        $this->view =& new EventEditView($mytemplate, $this->form);
        $thanks_view =& new EventThanksView($mytemplate2);
        $this->form->setView($this->view);

        $this->setDefaultView($this->view);

        $this->addView('success', WACT_DEFAULT_VIEW);
        $this->addView('notfound', WACT_DEFAULT_VIEW);
        $this->addView('delete', new Handle('RedirectView', array('/delete')));
        $this->addView('index', new Handle('RedirectView', array('/')));
        //$this->addView('createOK', new Handle('RedirectView', array('/')));
        $this->addView('createOK', $thanks_view);
        $this->addView('saveOK', new Handle('RedirectView', array('/')));
        $this->addView('cleanOK',WACT_DEFAULT_VIEW);
        $this->addView('this', WACT_DEFAULT_VIEW);
    }
}

?>